<template>
  <!-- 购物车添加页 -->
  <div>
    <h4>已选商品</h4>
    <table>
      <thead>
        <tr>
          <th>id</th>
          <th>名称</th>
          <th>价格</th>
          <th>数量</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(shopItem, shopIndex) in cartProducts" :key="shopIndex">
          <td>{{ shopItem.id }}</td>
          <td>{{ shopItem.name }}</td>
          <td>{{ shopItem.price }}</td>
          <td>{{ shopItem.num }}</td>
          <td>
            <div class="del_btn" @click="delProduct(shopItem)">删除</div>
          </td>
        </tr>
        <tr v-if="!cartProducts.length">
          <td colspan="5">您的购物车空空如也。。。</td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";

export default {
  name: "cart",
  data() {
    return {
      // cartProducts: []
    };
  },
  computed: {
    ...mapGetters(["cartProducts"])
  },
  methods: {
    ...mapActions(["delProduct"])
  }
};
</script>

<style lang="scss" scoped>
@import "@/sass/cart/product.scss";
</style>